import os
import yaml

file_path = "E:\\JGAuto\TYTAPIAuto\\common\\token.yaml"

# 把token写到yaml文件中
def writeToken(token):

    # 当前路径
    # current_path = os.getcwd()
    # # 所处文件夹路径
    # dir_path = os.path.abspath(os.path.dirname(current_path)+os.path.sep+".")
    # # token文件路径
    # file_path = dir_path + "\\token.yaml"

    # 写入的内容
    t = {"token": token}
    with open(file_path, 'w', encoding='utf-8') as f:
        yaml.dump(t, stream=f, allow_unicode=True)


# 从yaml文件中获取token值
def readToken():

    f = open(file_path, 'r', encoding='utf-8')
    cfg = f.read()
    dic = yaml.load(cfg, Loader=yaml.FullLoader)
    token = dic["token"]

    return token